#coding:utf-8
# Echo server program -liujian
import socket
import time
import os
import threading

#reporters
reporters = [#'10.129.41.70',\
             '10.12.131.148',\
             '10.12.131.147',\
             '10.12.16.196',\
             '10.12.131.145',\
             '10.12.131.146',\
             '10.12.7.154',\
             '10.12.16.197',\
             '10.12.139.212',\
             '10.12.131.144',\
             '10.11.201.225',\
             '10.11.201.224',\
             '10.12.139.93',\
             '10.12.135.106',\
             '10.12.135.105',\
             '10.129.41.124',\
             '10.129.41.27',\
             '10.129.41.44']

def sendcmd(cmdstr,conn1):
    conn1.send(cmdstr+'\n')
    return True

def rerunone(IPaddress):
    conn2 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    try:
        err = conn2.connect_ex((IPaddress, 5985))
        print "===========>"+IPaddress+"<=============="    
    except:
        print "Something wrong!!!"
        return    
    time.sleep(0.1)
    if not err:
        print "send rerun"
        sendcmd('rerun',conn2)
        print "Send Done!"
    time.sleep(0.1)
    conn2.close()
           
if __name__=='__main__':
    #main()
    for i in reporters:
        rerunone(i)
    #rerunone("10.12.16.196")
     #print reporters
